import axios from 'axios'
import {store} from '@/store/store.js'
// const baseURL = 'yhc.sadhkl.com/'
// axios.defaults.baseURL = baseURL
import qs from 'qs'
// //请求拦截器
axios.interceptors.request.use(function (config){

  //设置请求头中的token
  // config.headers['Authorization'] = token
  config.headers.userKey = `${localStorage.getItem(`userKey`)}`
  // if(config.code == -10) {
  //      localStorage.removeTtem('userKey')
  // }
	return config
},function(error){
	return Promise.reject(error)
})

axios.interceptors.response.use(response => {
    if(response.data.code == -10) {
        localStorage.clear()
        //  localStorage.removeItem('userKey')
        //  localStorage.removeItem('username')
         //this.$router.push('/login')
        //  window.location.reload()
    }
    return response
})

// export function releaseAct(data) {
// return axios({method: 'post',url: `store/store/release`,data: JSON.stringify(data)}).then(res => {
//       return res.data
//    })
//  }

// export function
// Act(data) {
// return axios({method: 'post',url: `store/store/release`,data: JSON.stringify(data)}).then(res => {
//       return res.data
//    })
//  }
//上传活动图片
export const uploadAct = params => {
	return axios.post('api/upload/upload',params).then(res=>res.data);
}
//发布活动
export const releaseAct = params => {
    return axios.post('api/store/release', qs.stringify(params)).then(res => res.data)
}
//添加店铺
export const addStore = params => {
	return axios.post('api/store/shopAdd',qs.stringify(params)).then(res=>res.data)
}
//活动发布店铺获取
export const actGetStore = params =>{
	return axios.post('api/store/releaseShop',qs.stringify(params)).then(res=>res.data)
}
//添加评论
export const addComment = params =>{
	return axios.post('api/store/goodEvaluateAdd',qs.stringify(params)).then(res=>res.data)
}
//获取评论列表
export const getCommentList = params => {
	return axios.post('api/store/goodEvaluateList',qs.stringify(params)).then(res=>res.data)
}
//删除评论
export const deleteComment = params =>{
	return axios.post('api/store/goodEvaluateDel',qs.stringify(params)).then(res=>res.data)
}
//活动列表
export const actList = params => {
	return axios.post('api/store/releaseList',qs.stringify(params)).then(res=>res.data)
}
//佣金接口
export const commission = params => {
	return axios.post('api/store/commission',qs.stringify(params)).then(res=>res.data)
}
//核实活动信息
export const verifyInfo = params => {
  return axios.post('api/store/releaseVerify',qs.stringify(params)).then(res=>res.data)
}
// 店铺列表获取
export const bindStore = params => {
	return axios.post('api/store/shopList',qs.stringify(params)).then(res=>res.data)
}
//修改店铺
export const editStore = params => {
	return axios.post('api/store/shopEdit',qs.stringify(params)).then(res=>res.data)
}
//删除店铺
export const deleteStore = params => {
	return axios.post('api/store/shopDel',qs.stringify(params)).then(res=>res.data)
}
//登陆
export const login = params => {
   return axios.post('api/store/login',qs.stringify(params)).then(res=>res.data)
}
//注册
export const registered = params => {
	return axios.post('api/store/registered',qs.stringify(params)).then(res=>res.data)
 }
 //修改密码
export const userPasswordEdit = params => {
	return axios.post('api/store/userPasswordEdit',qs.stringify(params)).then(res=>res.data)
 }
//验证码
export const getcode = params => {
  return axios.post('api/msg/msgSend',qs.stringify(params)).then(res=>res.data)
}
/*
   短信验证密码找回
*/
// 1.发送验证码
export const sendCode = params => {
   return axios.post('api/msg/forgotMsgSend',qs.stringify(params)).then(res=>res.data)
}
//2.验证码判断
export const verify = params => {
   return axios.post('api/store/forgotPwdCode',qs.stringify(params)).then(res=>res.data)
}
//3.密码找回
export const getPasswordBack = params => {
   return axios.post("api/store/forgotPwd",qs.stringify(params)).then(res=>res.data)
}
//申诉中心
export const complaint = params => {
   return axios.post('api/store/complaint',qs.stringify(params)).then(res=>res.data)
}
//充值,type=1支付宝充值，type=2银行卡充值
export const recharge = params => {
  return axios.post('api/store/assetCharge',qs.stringify(params)).then(res=>res.data)
}
//充值记录 type=1是支付宝充值，type=2是银行卡充值
export const rechargeHistory = params => {
  return axios.post('api/store/assetChargeList',qs.stringify(params)).then(res=>res.data)
}
//资金明细
export const assetDetail = params => {
  return axios.post('api/store/assetDetail',qs.stringify(params)).then(res=>res.data)
}
//申诉中心
export const complaintList = params => {
   return axios.post('api/store/complaintList',qs.stringify(params)).then(res=>res.data)
}
//撤销申诉
export const complaintUndo = params => {
   return axios.post('api/store/complaintUndo',qs.stringify(params)).then(res=>res.data)
}
//查看详情
export const releaseView = params => {
   return axios.post('api/store/releaseView',qs.stringify(params)).then(res=>res.data)
}
//推广赚金
export const promote = params => {
   return axios.post('api/store/promote',qs.stringify(params)).then(res=>res.data)
}
//活动支付
export const goodsPay = params => {
   return axios.post('api/store/goodsPay',qs.stringify(params)).then(res=>res.data)
}
//订单列表
export const orderList = params => {
   return axios.post('api/store/orderList',qs.stringify(params)).then(res=>res.data)
}
//获取本金
export const getCaptial = params => {
   return axios.post('api/store/storeCost',qs.stringify(params)).then(res=>res.data)
}
//设置佣金
export const setCommission = params => {
   return axios.post('api/store/storeSet',qs.stringify(params)).then(res=>res.data)
}
//店铺获取url
export const getStore = params => {
   return axios.post('api/store/shopActivation',qs.stringify(params)).then(res=>res.data)
}
//店铺激活
export const activeStore = params => {
   return axios.post('api/store/shopActivationSet',qs.stringify(params)).then(res=>res.data)
}
//查询图片
export const getImg = params => {
   return axios.post('api/store/goodEvaluateCount',qs.stringify(params)).then(res=>res.data)
}
